/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/** **************************************************************************************
 *  \file     sdrv_lld_dpe.h
 *  \brief    This file contains interface header for dpe driver.
 *
 * <table>
 * <tr><th>Date           <th>Version
 * <tr><td>2024/10/29     <td>1.0.0
 * </table>
 *****************************************************************************************/

#ifndef DPE_IP_H
#define DPE_IP_H

#ifdef __cplusplus
extern "C" {
#endif

#include "lld_platform.h"

#define DPE_VCAN_CH_NUM (16U)
#define DPE_DIAG_VCAN_CH_ID (0xFFU)
#define DPE_CAN_NUM (16U)
#define DPE_VCAN_SEND_STAT_SLOT_NUM (16U)
#define DPE_SUBQUEUE_NUM (8U)
#define DPE_PFC_NUM (32U)

#define DPE_MAX_RTLB_INDEX_ENTRY_NUM (2048U)
#define DPE_RTLB_INDEX_SIZE (8U)
#define DPE_MAX_RTLB_INDEX_SIZE (DPE_MAX_RTLB_INDEX_ENTRY_NUM * DPE_RTLB_INDEX_SIZE)

#define DPE_VCAN_FIFO_ELEMENT_SIZE (0x50U)
#define DPE_DVCAN_FIFO_ELEMENT_SIZE (0x50U)

#define DPE_VCAN_RX_FIFO_ELEMENT_NUM (16U)
#define DPE_VCAN_RX_FIFO_SIZE (DPE_VCAN_FIFO_ELEMENT_SIZE * DPE_VCAN_RX_FIFO_ELEMENT_NUM)
#define DPE_VCAN_TX_FIFO_ELEMENT_NUM (16U)
#define DPE_VCAN_TX_FIFO_SIZE (DPE_VCAN_FIFO_ELEMENT_SIZE * DPE_VCAN_TX_FIFO_ELEMENT_NUM)
#define DPE_DVCAN_FIFO_ELEMENT_NUM (16)
#define DPE_DVCAN_FIFO_SIZE (DPE_DVCAN_FIFO_ELEMENT_SIZE * 16)

#define DPE_OK (0U)
#define DPE_NOK (1U)
#define DPE_BUSY (2U)

/** @brief DPE bus id definition. */
typedef enum
{
    DPE_CAN1 = 0U,
    DPE_CAN2 = 1U,
    DPE_CAN3 = 2U,
    DPE_CAN4 = 3U,
    DPE_CAN5 = 4U,
    DPE_CAN6 = 5U,
    DPE_CAN7 = 6U,
    DPE_CAN8 = 7U,
    DPE_CAN9 = 8U,
    DPE_CAN10 = 9U,
    DPE_CAN11 = 10U,
    DPE_CAN12 = 11U,
    DPE_CAN13 = 12U,
    DPE_CAN14 = 13U,
    DPE_CAN15 = 14U,
    DPE_CAN16 = 15U,
    DPE_VCAN1 = 32U,
    DPE_VCAN2 = 33U,
    DPE_VCAN3 = 34U,
    DPE_VCAN4 = 35U,
    DPE_VCAN5 = 36U,
    DPE_VCAN6 = 37U,
    DPE_VCAN7 = 38U,
    DPE_VCAN8 = 39U,
    DPE_VCAN9 = 40U,
    DPE_VCAN10 = 41U,
    DPE_VCAN11 = 42U,
    DPE_VCAN12 = 43U,
    DPE_VCAN13 = 44U,
    DPE_VCAN14 = 45U,
    DPE_VCAN15 = 46U,
    DPE_VCAN16 = 47U,
    DPE_Diag_vCAN = 63U
} Dpe_BusIdType;

/** @brief DPE VCAN drop reason. */
typedef enum
{
    /* b00: flushed. */
    DPE_VCAN_FLUSHED = 0U,
    /* b01: filtered. */
    DPE_VCAN_FILTERED = 1U,
    /* b10: replaced. */
    DPE_VCAN_REPLACED = 2U,
    /* b11: unknown or wrong DLC packet. */
    DPE_VCAN_UNEXPECTED = 3U
} Dpe_VcanDropReasonType;

/** @brief DPE subqueue arbitration scheme. */
typedef enum
{
    /* b00: packet fifo mode */
    DPE_SUBQUEUE_ARBIT_FIFO = 0U,
    /* b01: sending the small frame id first */
    DPE_SUBQUEUE_ARBIT_MPFO = 1U
} Dpe_SubqueueArbitSchemeType;

/** @brief DPE PFC frame id match mode. */
typedef enum
{
    /* b00: FFID_START < frame id <= FFID_END */
    PFC_FRAMEID_MATCH_MODE_IN_RANGE = 0U,
    /* b01: frame id <= FFID_START */
    PFC_FRAMEID_MATCH_MODE_LESS_EQ = 1U,
    /* b10: frame id > FFID_END */
    PFC_FRAMEID_MATCH_MODE_GREATER = 2U,
    /* b11: frame id < FFID_START or frame id > FFID_END */
    PFC_FRAMEID_MATCH_MODE_OUT_RANGE =3U
} Pfc_FrameIdMatchModeType;

/** @brief DPE PFC action type. */
typedef enum
{
    /* b00: the filtered packet will be dropped. */
    PFC_ACTION_TYPE_DROP = 0U,
    /* b01: the filtered packet will be routed to diag vcan. */
    PFC_ACTION_TYPE_MIRROR_TO_DVCAN = 1U,
    /* b1x: the filtered packet will be routed to specific CAN bus. */
    PFC_ACTION_TYPE_MIRROR_TO_CAN = 2U
} Pfc_ActionType;

/** @brief DPE PFC bus direction selection. */
typedef enum
{
    /* b0: filter is based on the receiver. */
    PFC_BUS_DIRECTION_SEL_REC = 0U,
    /* b1: filter is based on the transmitter. */
    PFC_BUS_DIRECTION_SEL_SEND = 1U
} Pfc_BusDirectionSelType;

/** @brief DPE VCAN status. */
typedef enum
{
    /* VCAN receive packet. */
    DPE_VCAN_REC = 0U,
    /* VCAN rev drop occured. */
    DPE_VCAN_REC_DROP = 1U,
    /* VCAN send packet done. */
    DPE_VCAN_SEND_DONE = 2U,
    /* VCAN send packet timeout occured. */
    DPE_VCAN_SEND_TIMEOUT = 3U,
    /* VCAN send packet flushed. */
    DPE_VCAN_SEND_FLUSHED = 4U,
    /* VCAN send packet filtered. */
    DPE_VCAN_SEND_FILTERED = 5U,
    /* VCAN send packet replaced. */
    DPE_VCAN_SEND_REPLACED = 6U,
    /* VCAN send unknown or wrong DLC packet dropped. */
    DPE_VCAN_SEND_UNEXPECTED = 7U,
    /* VCAN send status is invalid. */
    DPE_VCAN_SEND_STATUS_INVALID = 8U
} Dpe_VcanStatusType;

/**
 * @brief DPE VCAN interrupt enable.
 *
 * send done, timeout, drop interrupts are only valid for vcan.
 */
typedef enum
{
    /* VCAN rec interrupt enable. */
    DPE_VCAN_REC_INT_ENABLE = 0x1U,
    /* VCAN rec packet dropped interrupt enable. */
    DPE_VCAN_REC_DROP_INT_ENABLE = 0x2U,
    /* VCAN send packet done interrupt enable. */
    DPE_VCAN_SEND_DONE_INT_ENABLE = 0x4U,
    /* VCAN send packet timeout interrupt enable. */
    DPE_VCAN_SEND_TIMEOUT_INT_ENABLE = 0x8U,
    /* VCAN send packet drop interrupt enable. */
    DPE_VCAN_SEND_DROP_INT_ENABLE = 0x10U
} Dpe_VcanIntEnableType;

/** @brief DPE CAN message buffer mode. */
typedef enum
{
    /* b0: 8 bytes mode. */
    DPE_CAN_MB_MODE_8BYTES = 0U,
    /* b1: 64 bytes mode. */
    DPE_CAN_MB_MODE_64BYTES = 1U
} Dpe_CanMbModeType;

/** @brief DPE CAN message buffer select type. */
typedef enum
{
    /* b0: message buffer 21~27. */
    DPE_CAN_MB_SEL_21_27 = 0U,
    /* b1: message buffer 7~13. */
    DPE_CAN_MB_SEL_7_13 = 1U
} Dpe_CanMbSelType;

/** @brief DPE CAN frame protocol type. */
typedef enum
{
    /* Standard classic CAN */
    DPE_CAN_FRAME_PROT_STD_CC = 0U,
    /* Standard CANFD */
    DPE_CAN_FRAME_PROT_STD_FD = 1U,
    /* Extended classic CAN */
    DPE_CAN_FRAME_PROT_EXT_CC = 2U,
    /* Extended CANFD */
    DPE_CAN_FRAME_PROT_EXT_FD = 3U
} Dpe_CanFrameProtType;

/** @brief DPE PFC configuration type. */
typedef struct
{
    /* Frame id match mode. */
    Pfc_FrameIdMatchModeType matchMod;
    /* PFC action type. */
    Pfc_ActionType actType;
    /* PFC bus direction selection. */
    Pfc_BusDirectionSelType dirSel;
    /* DPE bus id, refer to @Dpe_BusIdType */
    Dpe_BusIdType busId;
    /* CAN frame protocol type. */
    Dpe_CanFrameProtType frameProt;
    /* Frame id start value. */
    uint32_t frameidStart;
    /* Frame id end value. */
    uint32_t frameidEnd;
} Dpe_PfcCfgType;

/** @brief DPE VCAN frame type. */
typedef struct
{
    /* CAN Frame Identifier. */
    uint32_t id;
    /* Payload length in bytes(Range: 0~64). */
    uint32_t length;
    /* EXT or STD format. */
    bool isExtend;
    /* CANFD or classic. */
    bool isCanfd;
    /* Padding value for CANFD payload. */
    uint8_t paddingVal;
    /* Pointer to payload data. */
    uint8_t *dataBuffer;
} DpeVcan_FrameType;

/**
 * @brief DPE CAN message buffer configuration type.
 *
 * FlexCAN message buffer information for dpe.
 */
typedef struct
{
    /* Message buffer start address. */
    uint16_t mbStartOffset;
    /* CAN message buffer select. */
    Dpe_CanMbSelType mbSel;
    /* CAN message buffer region payload mode. */
    Dpe_CanMbModeType mbMod;
} Dpe_CanMbCfgType;

/**
 * @brief dpe vcan transfer callback function.
 *
 * @note This callback function will be called in DPE interrupt context,
 * so it should be short and fast.
 *
 * @param[in] arg HLD defined argument.
 * @param[in] status Vcan transfer status both for send and receive.
 * @param[in] frame received vcan frame.
 * @param[in] result Result of vcan transfer, packetId for send or source busId for receive.
 */
typedef void (*DpeVcan_CallbackFuncType)(void *arg, Dpe_VcanStatusType status, DpeVcan_FrameType *frame,
                                            uint32_t result);

/**
 * @brief Configure specific vcan channel.

 * @note If cacheable memory used, rxFifoAddr and rxFifoSize must be aligned with cache line.
 * If TxDrop is enabled, vcan tx packet will be dropped if it can't be routed to txqueue in time.
 *
 * It's recommended to disable txDrop for vcan channel,
 * otherwise it may cause lose of vcan frame and no drop reason will report.
 * enableTxDrop is meaningless for diag vcan.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] vcanId Vcan channel id between 0 and 15 or diag vcan.
 * @param[in] rxFifoAddr RxFifo address for vcan channel.
 * @param[in] enableTxDrop True for enable tx drop, false for disable.
 */
extern void DpeVcan_Lld_Config(uint32_t dpeBase, uint8_t vcanId,  uint32_t rxFifoAddr, bool enableTxDrop);

/**
 * @brief Enable specific vcan channel interrupt.
 *
 * @note intEnable refer to @Dpe_VcanIntEnableType.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] vcanId Vcan channel id between 0 and 15 or diag vcan.
 * @param[in] intEnable Vcan Int Enable for vcan channel.
 */
extern void DpeVcan_Lld_EnableInt(uint32_t dpeBase, uint8_t vcanId, uint8_t intEnable);

/**
 * @brief Disable specific vcan channel interrupt.
 *
 * @note intEnable refer to @Dpe_VcanIntEnableType.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] vcanId Vcan channel id between 0 and 15 or diag vcan.
 * @param[in] intEnable Vcan Int Enable for vcan channel.
 */
extern void DpeVcan_Lld_DisableInt(uint32_t dpeBase, uint8_t vcanId, uint8_t intEnable);

/**
 * @brief Get vcan channel interrupt status.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] vcanId Vcan channel id between 0 and 15 or diag vcan.
 * @retval uint32_t Vcan Int Status for vcan channel.
 */
extern uint32_t DpeVcan_Lld_GetIntStatus(uint32_t dpeBase, uint8_t vcanId);

/**
 * @brief Get vcan channel interrupt enable.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] vcanId Vcan channel id between 0 and 15 or diag vcan.
 * @retval uint32_t Vcan Int Enable for vcan channel.
 */
extern uint32_t DpeVcan_Lld_GetIntEnable(uint32_t dpeBase, uint8_t vcanId);

/**
 * @brief Clear vcan channel interrupt status.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] vcanId Vcan channel id between 0 and 15 or diag vcan.
 * @param[in] intStatus Int Status of vcan channel.
 */
extern void DpeVcan_Lld_ClearIntStatus(uint32_t dpeBase, uint8_t vcanId,
                                        uint32_t intStatus);

/**
 * @brief DPE vcan irq handler for send status.
 *
 * @note The status slot cannot be checked whether it is in the ISR or not, so if tx polling mode is used,
 * this function must not be called in the ISR, and DPE_VCANINTEN_VCAN_SEND_DONE_MASK,
 * DPE_VCANINTEN_VCAN_SEND_TIMEOUT_MASK and DPE_VCANINTEN_VCAN_SEND_DROP_MASK should be polled in mainfunction.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] vcanId Vcan channel id between 0 and 15 or diag vcan.
 * @param[in] callback Callback function for vcan irq.
 * @param[in] arg Argument for callback function.
 */
extern void DpeVcan_Lld_HandleSendStatus(uint32_t dpeBase, uint8_t vcanId,
                                            DpeVcan_CallbackFuncType callback, void *arg);

/**
 * @brief Start specific vcan channel.
 *
 * @note Bit 0 of intEnable is for rec, and bit 1 is for rec drop,
 * which applies to both vcan and diag vcan.
 * Bit 2 of intEnable is for send done, bit 3 is for send timeout, and bit 4 is for send drop,
 * which applies to vcan only.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] vcanId Vcan channel id between 0 and 15 or diag vcan.
 * @param[in] intEnable Vcan Int Enable for vcan channel.
*/
extern void DpeVcan_Lld_Start(uint32_t dpeBase, uint8_t vcanId, uint8_t intEnable);

/**
 * @brief Stop specific vcan channel.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] vcanId Vcan channel id between 0 and 15 or diag vcan.
 */
extern void DpeVcan_Lld_Stop(uint32_t dpeBase, uint8_t vcanId);

/**
 * @brief Write vcan frame to vcan tx fifo.
 *
 * @note Upper layer maintains a tx FIFO with a depth of 16, where the address and size are
 * aligned with the cache line. When a VCAN packet is transmitted by the real bus or dropped,
 * the packet ID will be notified to the upper layer.
 * If memory is cacheable, sync-write opration which contains clean-cache is required refer to
 * macro @DPE_SYNC_WRITE_BUFFER_RANGE.
 * If non-cacheable memory used by DPE, dmb is required.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] vcanId Vcan channel id between 0 and 15 or diag vcan.
 * @param[in] txPacketAddr tx packet address for one element of tx fifo.
 * @param[in] frame Vcan frame to be written.
 * @param[in] packetId PacketId for this vcan frame.
 * @retval 0 for write success, 2 for vcan txfifo is full.
 */
extern int DpeVcan_Lld_Write(uint32_t dpeBase, uint8_t vcanId, uint32_t *txPacketAddr,
                                    DpeVcan_FrameType *frame, uint32_t packetId);

/**
 * @brief Read vcan frame from vcan rx fifo.
 *
 * Source bus of packet can be parsed for vcan.
 *
 * @note If cacheable memory used by DPE, sync-read opration which contains invalidate-cache is required
 * refer to macro @DPE_SYNC_READ_BUFFER_RANGE.
 * If non-cacheable memory used by DPE, sync-read opration can be NULL.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] vcanId Vcan channel id between 0 and 15 or diag vcan.
 * @param[out] frame Vcan frame to be read.
 * @param[out] srcBusId Source bus id for this vcan packet, bit[0:5] is bus id.
 * @retval 0 for read success. 1 for no frames in rx fifo.
 */
extern int DpeVcan_Lld_Read(uint32_t dpeBase, uint8_t vcanId, DpeVcan_FrameType *frame, uint8_t *srcBusId);

/**
 * @brief Polling vcan recv status.
 *
 * @note Polling DPE_VCANINTEN_VCAN_REC_MASK or DPE_VCANINTEN_VCAN_REC_DROP_MASK in mainfunction.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] vcanId Vcan channel id between 0 and 15 or diag vcan.
 * @param[in] pollingIntStat Polling Int Status of recv direction.
 * @param[in] callback Callback function for vcan send.
 * @param[in] arg Argument for callback function.
 */
extern void DpeVcan_Lld_RecvPolling(uint32_t dpeBase, uint8_t vcanId, uint8_t pollingIntStat,
                                        DpeVcan_CallbackFuncType callback, void *arg);

/**
 * @brief Polling vcan send status.
 *
 * @note DPE_VCANINTEN_VCAN_SEND_DONE_MASK, DPE_VCANINTEN_VCAN_SEND_TIMEOUT_MASK and
 * DPE_VCANINTEN_VCAN_SEND_DROP_MASK should be polled in mainfunction.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] vcanId Vcan channel id between 0 and 15 or diag vcan.
 * @param[in] pollingIntStat Polling Int Status of send direction.
 * @param[in] callback Callback function for vcan send.
 * @param[in] arg Argument for callback function.
 */
extern void DpeVcan_Lld_SendStatusPolling(uint32_t dpeBase, uint8_t vcanId, uint8_t pollingIntStat,
                                            DpeVcan_CallbackFuncType callback, void *arg);

/**
 * @brief DPE vcan irq handler.
 *
 * This function handles vcan rx, rx overflow, tx done, tx drop and tx timeout.
 *
 * @note Simultaneous occurrence of drop/done and timeout in one status slot can be avoided
 * by setting timeout only when mb sending cannot be finished.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] vcanId Vcan channel id between 0 and 15 or diag vcan.
 * @param[in] callback Callback function for vcan irq.
 * @param[in] arg Argument for callback function.
 */
extern void DpeVcan_Lld_IrqHandler(uint32_t dpeBase, uint8_t vcanId,
                                    DpeVcan_CallbackFuncType callback, void *arg);

/**
 * @brief Configure DPE routing table including both the index and context tables.
 *
 * @note Index of RTLB should be sorted in order.
 *
 * If memory for context of RTLB is cacheable, sync-write opration which contains clean-cache is
 * required refer to macro @DPE_SYNC_WRITE_BUFFER_RANGE.
 * If non-cacheable memory used by DPE, dmb is required.
 *
 * indexSizeInByte is aligned to 8-byte alignment, and contextSizeInByte is aligned with cache line.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] indexTblAddr Address of index table.
 * @param[in] indexSizeInByte Size of index table in byte.
 * @param[in] ctxTblAddr Address of context table.
 * @param[in] ctxSizeInByte Size of context table in byte.
 */
extern void Dpe_Lld_RoutingTableConfig(uint32_t dpeBase, uint32_t *indexTblAddr, uint32_t indexSizeInByte,
                                                    uint32_t *ctxTblAddr, uint32_t ctxSizeInByte);

/**
 * @brief Start DPE.
 *
 * @param[in] dpeBase DPE base address.
 */
extern void Dpe_Lld_Start(uint32_t dpeBase);

/**
 * @brief Stop DPE.
 *
 * @param[in] dpeBase DPE base address.
 * @retval 0 for success, 1 for failure.
 */
extern int Dpe_Lld_Stop(uint32_t dpeBase);

/**
 * @brief Configure DPE mirror bus.
 *
 * @note default mirror bus is diag vcan, bus refer to @Dpe_BusIdType.
 * For diag vcan, subQid can be any value which is meaningless.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] bus Mirror bus id.
 * @param[in] subQid SubQueue id.
 */
extern void Dpe_Lld_ConfigMirrorBus(uint32_t dpeBase, Dpe_BusIdType bus, uint32_t subQid);

/**
 * @brief Configure DPE subqueue.
 *
 * @note Subqueues that are not configured will use the default configuration.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] canId CAN bus index.
 * @param[in] subQid Index of subqueue from 0 to 7.
 * @param[in] scheme Arbitration scheme of subqueue.
 * @param[in] enReplace true for replace old packet with same frame ID.
 */
extern void Dpe_Lld_ConfigSubqueue(uint32_t dpeBase, uint8_t canId, uint8_t subQid,
                            Dpe_SubqueueArbitSchemeType scheme, bool enReplace);

/**
 * @brief Basic configuration for DPE CAN.
 *
 * @note Set all txqueues flushed before start txqueue is called.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] canId CAN bus id.
 * @param[in] canBufferBaseAddr Base address of txqueue buffer.
 * @param[in] canFDBaseAddr Base address of flexcan.
 * @param[in] canReqMask true for enable can request for DPE, false for disable.
 */
extern void Dpe_Lld_ConfigCan(uint32_t dpeBase, uint8_t canId, uint32_t canBufferBaseAddr,
                                uint32_t canFDBaseAddr, uint32_t canReqMask);

/**
 * @brief Configure DPE packet filter configuration.
 *
 * @note PFC can be used to filter out packets like blacklist or
 * mirror packets to assigned can bus or diag vcan.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] pfcIdx Index of packet filter configuration.
 * @param[in] cfg Pointer to packet filter configuration.
 */
extern void DpePfc_Lld_Config(uint32_t dpeBase, uint8_t pfcIdx, Dpe_PfcCfgType *cfg);

/**
 * @brief Enable or disable packet filter configuration.
 *
 * @note If pfc is enabled again, counter will be reset to 0.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] pfcIdx Index of packet filter configuration.
 * @param[in] en true for enable, false for disable.
 */
extern void DpePfc_Lld_Enable(uint32_t dpeBase, uint8_t pfcIdx, bool en);

/**
 * @brief Get counter of packet that hits pfc.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] pfcIdx Index of packet filter configuration.
 * @retval uint32_t Counter of packet which hit pfc.
 */
extern uint32_t DpePfc_Lld_GetCounter(uint32_t dpeBase, uint8_t pfcIdx);

/**
 * @brief Configure DPE txqueue.
 *
 * @note Txqueue configuration about mailbox for DPE must match with associated flexcan.
 * Default config for txqueue enable protocol convert and interrupt mode.
 * Timeout cnt value refer to macro @DPE_CAN_TXQUEUE_TIMEOUT_CNT.
 * Payload size for all regions of flexcan must be the same and either 64 bytes or 8 bytes.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] txqueueIdx Txqueue index according to CAN bus id.
 * @param[in] cfg Pointer to txqueue configuration.
 */
extern void DpeQueue_Lld_Config(uint32_t dpeBase, uint8_t txqueueIdx, Dpe_CanMbCfgType *cfg);

/**
 * @brief Start DPE txqueue for specific CAN bus.
 *
 * @note After started, txqueue will buffer new packets and send them to specific CAN bus.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] txqueueIdx Txqueue index according to CAN bus id.
 */
extern void DpeQueue_Lld_Start(uint32_t dpeBase, uint8_t txqueueIdx);

/**
 * @brief Stop DPE txqueue for specific CAN bus.
 *
 * After stopped, txqueue will not buffer new packets.
 *
 * @note mbInactived is used to indicate whether mailbox may lose can packet if has one.
 * SW need enable timeout if mbInactived is true if function for sw busoff recover or de-init called.
 *
 * @param[in] dpeBase DPE base address.
 * @param[in] txqueueIdx Txqueue index according to CAN bus id.
 * @param[in] mbInactived  true for mb has been inactived, false for mb hasn't been inactived.
 * @return int  0 for success. 1 for failure.
 */
extern int DpeQueue_Lld_Stop(uint32_t dpeBase, uint8_t txqueueIdx, bool mbInactived);

#ifdef __cplusplus
}
#endif

#endif /* DPE_IP_H */
/* End of file */
